﻿using System;
using System.Collections.Generic;

using System.Text;
using System.Web;

using Com.Framework.Cookie;
using Com.Framework.Enc;

namespace Com.Library.Cookie
{
    public class WebCookie : BaseCookie
    {
        private string m_SC = string.Empty;
        public WebCookie()
            : base(CookieUtil.DomainName)
        {
            GetCookie();
        }

        public bool IsLogin
        {
            get {
                if (UserID == string.Empty)
                    return false;
                return true;
            }
        }

		private int m_UserNo = 0;
		public int UserNo
		{
			get { return m_UserNo; }
		}

        private string m_UserID = string.Empty;
        public string UserID
        {
            get { return m_UserID; }
        }

        private string m_UserName = string.Empty;
        public string UserName
        {
            get { return m_UserName; }
        }

		private byte m_GroupType = 0;
		public byte GroupType
        {
			get { return m_GroupType; }
        }

		private string m_IsLocalUser = string.Empty;
		public string IsLocalUser
		{
			get { return m_IsLocalUser; }
		}

		private byte m_UserLevel = 0;
		public byte UserLevel
		{
			get { return m_UserLevel; }
		}
        
        private void GetCookie()
        {
            if (m_SC == string.Empty)
            {
                m_SC = GetEncCookie("SC");
            }
            this.m_UserNo = GetData(m_SC, "UserNo") == string.Empty ? 0 : Convert.ToInt32(GetData(m_SC, "UserNo"));
            this.m_UserID = GetData(m_SC, "UserID");
            this.m_UserName = GetData(m_SC, "UserName");
			this.m_GroupType = GetData(m_SC, "GroupType") == string.Empty ? (byte)0 : Convert.ToByte(GetData(m_SC, "GroupType"));
			this.m_IsLocalUser = GetData(m_SC, "IsLocalUser");
			this.m_UserLevel = GetData(m_SC, "UserLevel") == string.Empty ? (byte)0 : Convert.ToByte(GetData(m_SC, "UserLevel"));
        }

        public void ResetCookie()
        {
            GetCookie();
        }
    }
}
